home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 43
/
Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso
/
-serious-
/
comms
/
other
/
ascan
/
sources
/
ddelay.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-14
|
2KB
|
78 lines
#include "ascan.h"
#include <proto/timer.h>
/***************************************************************************/
/* delay functions using timer.device, not so much to say*/
LONG setDStruct(struct dstruct *ds)
{
if ((ds->sigBit=AllocSignal(-1))==-1)
return FALSE;
INITPORT(&ds->dport,ds->sigBit);
INITMESSAGE(MESSAGE(&ds->dtr),&ds->dport,sizeof(struct timerequest));
if (OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest*)&ds->dtr,0)) {
FreeSignal(ds->sigBit);
ds->sigBit=-1;
return FALSE;
}
ds->flags = DSFLG_ALLOCATED;
return TRUE;
}
/***************************************************************************/
void freeDStruct(struct dstruct *ds)
{
if (ds->flags & DSFLG_ALLOCATED) {
if (ds->flags & DSFLG_ACTIVE) stopDelay(ds);
CloseDevice((struct IORequest *)&ds->dtr);
FreeSignal(ds->sigBit);
ds->flags &= ~DSFLG_ALLOCATED;
}
}
/***************************************************************************/
ULONG doDelay(struct dstruct *ds,ULONG secs,ULONG micros,ULONG signals)
{
register ULONG rec;
ds->dtr.tr_node.io_Command = TR_ADDREQUEST;
ds->dtr.tr_time.tv_secs = secs;
ds->dtr.tr_time.tv_micro = micros;
SendIO((struct IORequest *)&ds->dtr);
rec = Wait((1<<ds->sigBit)|signals);
AbortIO((struct IORequest *)&ds->dtr);
WaitIO((struct IORequest *)&ds->dtr);
return rec;
}
/***************************************************************************/
void startDelay(struct dstruct *ds,ULONG secs,ULONG micros)
{
ds->flags |= DSFLG_ACTIVE;
ds->dtr.tr_node.io_Command = TR_ADDREQUEST;
ds->dtr.tr_time.tv_secs = secs;
ds->dtr.tr_time.tv_micro = micros;
SendIO((struct IORequest *)&ds->dtr);
}
/***************************************************************************/
void stopDelay(struct dstruct *ds)
{
if (ds->flags & DSFLG_ACTIVE) {
AbortIO((struct IORequest *)&ds->dtr);
WaitIO((struct IORequest *)&ds->dtr);
ds->flags &= ~DSFLG_ACTIVE;
}
}
/***************************************************************************/